package online_exams.service.impl;

import cn.dev33.satoken.secure.BCrypt;
import online_exams.domain.TUserEntity;
import online_exams.mapper.AdminMapper;
import online_exams.mapper.TUserMapper;
import online_exams.service.AdminService;
import online_exams.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class AdminServiceImpl implements AdminService {
    @Autowired
    private AdminMapper adminMapper;

    @Override
    public TUserEntity getUser(TUserEntity tUserEntity) {
        return adminMapper.getUser(tUserEntity);
    }

    @Override
    public Integer addUser(TUserEntity tUserEntity) {
        tUserEntity.setPassword(BCrypt.hashpw(tUserEntity.getPassword(), BCrypt.gensalt(15)));
        return adminMapper.addUser(tUserEntity);
    }

    @Override
    public int getUserTotal(TUserEntity tUserEntity) {
        // 实现查询总记录数的逻辑
        return adminMapper.selectTotal(tUserEntity);
    }

    @Override
    public List<TUserEntity> getUserListPage(TUserEntity tUserEntity, int offset, Integer pageSize) {
        // 实现分页查询的逻辑
        return adminMapper.selectPage(tUserEntity, offset, pageSize);
    }

    @Override
    public Integer updatePassword(TUserEntity tUserEntity) {
        tUserEntity.setPassword(BCrypt.hashpw(tUserEntity.getPassword(), BCrypt.gensalt(15)));
        return adminMapper.updatePassword(tUserEntity);
    }

    @Override
    public Integer updateUser(TUserEntity tUserEntity) {
        return adminMapper.updateUser(tUserEntity);
    }

}
